import Vue from 'vue'
import App from './App.vue'
import router from './router'
import Vant from 'vant'
import store from '@/store'
import 'vant/lib/index.css'
import 'lib-flexible/flexible'
Vue.use(Vant)
Vue.config.productionTip = false

// 定义全局时间格式化方法
Vue.filter('formatDate', (value, format) => {
  const date = new Date(value)
  const year = date.getFullYear()

  if (/(y+)/.test(format)) {
    const content = RegExp.$1
    format = format.replace(content, year)
  }
  const o = {
    M: date.getMonth() + 1,
    d: date.getDate(),
    h: date.getHours(),
    m: date.getMinutes(),
    s: date.getSeconds()
  }
  for (const key in o) {
    // 构造动态正则
    const reg = new RegExp(`(${key}+)`)
    // ;
    if (reg.test(format)) {
      // 获取匹配组的内容
      const content = RegExp.$1

      const k =
        o[key] >= 10 ? o[key] : content.length === 2 ? '0' + o[key] : o[key]
      format = format.replace(content, k)
    }
  }
  return format
})
new Vue({
  store,
  router,
  render: h => h(App)
}).$mount('#app')
